package com.ninjas.module.common.page;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PageAspect {

    @Pointcut("@annotation(com.ninjas.module.common.page.Page)")
    public void pageAnnotatedMethods() {}

    @Around("pageAnnotatedMethods()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            PageUtils.startPage();
            return joinPoint.proceed();
        } finally {
            PageUtils.clearPage();
        }
    }
}
